﻿using OASystem.Model;
using OASystem.ViewModel;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.BLL
{
    public class SelectListService : BaseService<Trainlist>
    {
        #region 编辑要从数据库查询数据再进行修改操作
        /// <summary>
        /// 编辑要从数据库查询数据再进行修改操作
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Trainlist SelectInfoMangers(int id)
        {
            return Query(a => a.Id == id);

        }
        #endregion                 

        #region 我的培训列表显示
        /// <summary>
        /// 我的培训列表显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ResponseResult GetMoudelList(int page, int limit, int userId, string title, string speaker, string date, Expression<Func<Trainlist, int>> orderbyLambda, out int count)
        {
            ResponseResult result = new ResponseResult();
            //根用户名ID条件查询数据
            Expression<Func<Trainlist, bool>> whereLambda = a => a.UserId == userId;
            //再根据条件显示数据
            List<Trainlist> trainlist = QueryList(whereLambda);

            //DateTime dt;
            //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
            //dtFormat.ShortDatePattern = "yyyy/MM/dd";
            //dt = Convert.ToDateTime(demo, dtFormat);
             DateTime kk = Convert.ToDateTime(date);

            if (!string.IsNullOrEmpty(title))
            {
                trainlist = trainlist.Where(a => a.TrainTitle.Contains(title) && a.UserId == userId).ToList();
            }
            if (!string.IsNullOrEmpty(speaker))
            {
                trainlist = trainlist.Where(a => a.Speaker.Contains(speaker) && a.UserId == userId).ToList();
            }
            if (!string.IsNullOrEmpty(date))
            {
                trainlist = trainlist.Where(a => a.StartTime == kk && a.UserId == userId).ToList();
            }
            if (trainlist != null)
            {
                count = trainlist.Count;
                result.data = trainlist;
            }
            else
            {
                count = 0;
            }
            return result;
        }
        #endregion

        #region 培训管理的列表显示
        /// <summary>
        /// 培训管理列表显示的查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="title"></param>
        /// <param name="speaker"></param>
        /// <param name="time"></param>
        /// <param name="orderbyLambda"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public ResponseResult TrainGetList(int page, int limit, string title, string speaker,string dates, Expression<Func<Trainlist, int>> orderbyLambda, out int count)
        {
            ResponseResult result = new ResponseResult();
            DateTime kk = Convert.ToDateTime(dates);
            //查询所有
            Expression<Func<Trainlist, bool>> whereLambda = a =>true;
            if (!string.IsNullOrEmpty(title))
            {
                //根据标题进行刷选
                whereLambda = a => a.TrainTitle.Contains(title);
            }
            if (!string.IsNullOrEmpty(speaker))
            {
                //根据演讲者进行筛选
                whereLambda = a => a.Speaker.Contains(speaker);
            }
            if (!string.IsNullOrEmpty(dates))
            {
                //根据时间进行刷选
                whereLambda = a => a.StartTime == kk;

            }
            //查询结果
            List<Trainlist> trainlist = QueryList(whereLambda);
            
            if (trainlist != null)
            {
                count = trainlist.Count;
                result.data = trainlist;
            }
            else
            {
                count = 0;
            }
            return result;
        }
        #endregion

       
    }
}

